package com.sdc.taglibs;

import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class Data extends SimpleTagSupport {
	/**
	 *
	 */
	private static final long serialVersionUID = -2388827699598753334L;
	private Date data = null;
	private String pattern = null;

	public Data() {
		super();
	}

	public void doTag() throws JspException, IOException {

		try {
			JspWriter out = this.getJspContext().getOut();
			SimpleDateFormat sdf = new SimpleDateFormat(pattern);
			out.print(sdf.format(this.data));
		} catch (Exception e) {
			throw new JspException(e.getMessage());
		}
	}

	public String getPattern() {
		return pattern;
	}

	public void setPattern(String pattern) {
		this.pattern = pattern;
	}

	public String getData() {
		SimpleDateFormat sdf = new SimpleDateFormat(pattern);
		return sdf.format(data);
	}

	public void setData(String data) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
		if (data != null) {
			try {
				this.data = sdf.parse(data);
			} catch (ParseException e) {
				e.printStackTrace();
			}
		}
	}

}
